package com.struct.graph.server_list
{
	import com.collection.ACollection;
	import com.component.ComponentChildren;
	import com.component.button.Button;
	import com.events.ServerListSelectEvent;
	import com.utils.Utils;
	
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	
	public class ServerListShow extends ComponentChildren
	{
		private var btnSubmit:Button;
		private var dispatcher:EventDispatcher;
		
		public function ServerListShow(name:String, dispatcher:EventDispatcher)
		{
			super();
			this.name = name;
			this.dispatcher = dispatcher;
			width = 190;
			height = 90;
			graphics.beginFill(0x00);
			graphics.drawRect(0, 0, width, height);
			graphics.drawRect(2, 2, width - 4, height - 4);
			graphics.endFill();
			
			Utils.createTextField(this, 5, 5, name, 12, 0, true);
			Utils.createTextField(this, 5, 30, "速度:", 12, 0, true);
			var speed:int = Math.ceil(Math.random() * 10);
			var color:uint;
			if(speed < 3){
				color = 0xff0000;
			} else if(speed < 6){
				color = 0xffcc00;
			} else if(speed < 8) {
				color = 0x00ffff;
			} else {
				color = 0x00ff00;
			}
			graphics.beginFill(color)
			for(var i:uint = 0; i < speed; ++i){
				graphics.drawRect(45 + i * (8 + 3), 31, 8, 15);
			}
			graphics.endFill();
			
			btnSubmit = new Button("进入");
			btnSubmit.x = 60;
			btnSubmit.y = 55;
			addChild(btnSubmit);
			btnSubmit.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		private function clickHandler(e:MouseEvent):void{
			dispatcher.dispatchEvent(new ServerListSelectEvent(ACollection.SELECTED, this));
		}
	}
}